//****************************************************************/
//Creation History
// Company: GZ Office
// NAME:    Exiry Chang Pass Word
// TITLE:   Change pass word when login   
// BY:      Recher
// DATE:    2003/2/21
//******************************************************************/
package admin;

import java.sql.*;

 public class JisEncrypt 
 {
    private Connection conn=null;
    //-------------------------
    public JisEncrypt(Connection con)
    {  
      //CR Log no: no begin of, remove the connection factory and input the Connection
      conn=con;  

   }
    //-------------------------------
    public String Encrypt(String pwd)
    {
        
        String plainText = pwd.trim();
        if (plainText.equals(""))  return "";
        String encryptText = "";
        String SqlStr = "select hthk_des3.encrypt('"+plainText+"') as encryptText from dual";
        try{
            Statement state=conn.createStatement();
            ResultSet rs=state.executeQuery(SqlStr);
            while(rs.next()){
                encryptText = rs.getString("encryptText");
            }
        }
        catch (Exception exception) { } 
        return encryptText;    
    }
    //----------------------------
    public boolean checkPWD(String upwd,String epwd)
    {
        String SqlStr = "select hthk_des3.equals('"+upwd+"','"+epwd+"')  as result from dual";
        try {
            Statement stmt=conn.createStatement();
            ResultSet rs=stmt.executeQuery(SqlStr);
            while (rs.next())
            {
                if(rs.getInt("result")==0)
                    return true; 
                else
                    return false;
                }
            }
        catch (Exception e)
        {
            System.out.println(e);
         }
         //
        return false;
    }
    //-----------------------------------------------
}    
//-------------------------------------------------------------